package sel.me.spring.boot245.web.config.security.handler;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;
import sel.me.spring.boot245.web.utils.ResultUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author shenenlu
 * @date 2021-7-28 18:58
 */
@Component
public class UserLogoutSuccessHandler implements LogoutSuccessHandler {


    /**
     * 用户登出返回结果
     * 这里应该让前端清除掉Token
     * @Author youcong
     */
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication){
        SecurityContextHolder.clearContext();
        ResultUtil.responseJson(response, ResultUtil.resultSuccess("登出成功"));
    }
}
